<template>
  <a-modal
    width="550px"
    :bodyStyle="{ height: '100px', overflow: 'auto', zIndex: 9999,}"
    title="文书送达"
    :visible="isModal"
    @cancel="handleCancel"
  >
    <span class="notice_content">{{ arriveDetail.content }}</span>
    <template slot="footer">
      <div style="display: flex; justify-content: flex-end;">
        <a-button class="m-r-8 btn_normal_color" style="margin-right: 20px" @click="handleCancel">暂不处理</a-button>
        <a-button class="m-r-8 btn_primary_color" type="primary" @click="toExecute" :loading="loading">
          前往送达
        </a-button>
      </div>
    </template>
  </a-modal>
</template>

<script>
import { getByApplyid } from '@/api/arrive/apl_arrive_details'
import { getReviewById } from '@/api/accept/apl_admreview'
import moment from 'moment'
export default {
    props: {
      applyid: {
        // 申请id
        type: String,
        required: true
      }
    },
    data () {
        return {
          loading: false,
          isModal: false,
          arriveDetail: {}
        }
    },
    created () {},
    methods: {
      async init () {
        const res = await getByApplyid(this.applyid)
        if (res.code == 0) {
          if (res.data) {
            this.isModal = true
            this.arriveDetail = res.data
          } else {
            this.handleCancel()
          }
        } else {
          console.log('查询待送达记录失败', res.msg)
          this.handleCancel()
        }
      },
      handleCancel () {
        this.isModal = false
        this.$emit('modalCancel')
      },
      // 处理通知任务
      async toExecute () {
        // 查询当前案件的基本信息
        this.loading = true
        const res = await getReviewById(this.applyid).finally(() => { this.loading = false })
        if (res.code == 0) {
          const result = res.data
          this.arriveDetail.status = result.status
          this.arriveDetail.status_text = result.status_text
          if (this.arriveDetail.warntime) {
            this.arriveDetail.leftDay = moment(this.arriveDetail.warntime).diff(moment(new Date()), 'days')
          } else {
            this.arriveDetail.leftDay = undefined
          }
          this.$router.push({
            path: `/ArriveInfoAdd/${this.applyid}`,
            query: {
              url: '/ArriveInfo',
              queryParam: this.arriveDetail
            }
          })
          this.isModal = false
        } else {
          this.$message.error('获取基本信息失败')
        }
      }
    }
}
</script>

<style>

  .notice_content {
    font-weight: 400;
    font-size: 14px;
    color: #2C2C2C;
  }
</style>
